package nullby.yoga.activity;

import java.util.Locale;

import nullby.yoga.R;
import nullby.yoga.utils.PrefManager;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.res.Configuration;
import android.support.v4.app.FragmentActivity;

import com.flurry.android.FlurryAgent;

public abstract class CommonActivity extends FragmentActivity {

	protected abstract void initView();

	public void setLang() {

		String languageToLoad = (PrefManager.get().getLang() == "") ? Locale
				.getDefault().getLanguage() : PrefManager.get()
				.getLang();

		if (PrefManager.get().getLang() == "") {
			PrefManager.get().putLang(languageToLoad);
		}

		Locale locale = new Locale(languageToLoad);

		Locale.setDefault(locale);

		Configuration config = new Configuration();
		config.locale = locale;
		getBaseContext().getResources().updateConfiguration(config,
				getBaseContext().getResources().getDisplayMetrics());

	}

	public void showAlert(Context context, String title, String text) {
		Builder alertBuilder = new Builder(context);
		alertBuilder.setTitle(title);
		alertBuilder.setMessage(text);
		alertBuilder.create().show();
	}

	@Override
	protected void onPause() {
		super.onPause();
		overridePendingTransition(R.anim.in, R.anim.out);
	}

	public void onStart() {
		super.onStart();
		FlurryAgent.onStartSession(this,
				getResources().getString(R.string.flurry_api_key));
	}

	public void onStop() {
		super.onStop();
		FlurryAgent.onEndSession(this);
		// your code
	}

}
